﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;
using BLL;

namespace Web
{
    public partial class admin_login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null) {
                Response.Redirect("admin_index.aspx");
            }
        }

        protected void btn_Login_Click(object sender, ImageClickEventArgs e)
        {
            AdminInfo admininfo = new AdminInfo();
            admininfo.UserName = this.txt_UserName.Value.ToString();
            admininfo.Password = this.txt_Password.Value.ToString();

            int isSucess = AdminInfoLogic.GetOneAdminInfo(admininfo);
            if (isSucess == 1)
            {
                Session["UserName"] = admininfo.UserName;
                Session["UserID"] = admininfo.AdminID;
                if (Request.QueryString["rtn"] == null)
                {
                    Response.Redirect("admin_index.aspx");
                }
                else
                {
                    Response.Redirect("~/"+Request.QueryString["rtn"].ToString());
                }
            }
        }
    }
}
